/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.icq.gui.dialogs.Renderer;

import java.awt.Component;
import java.util.Map;
import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JList;
import org.apache.log4j.Logger;

/**
 *
 * @author Носов А.В.
 */
public class IconListRenderer extends DefaultListCellRenderer {

    // Variables declaration
    private static final Logger log = Logger.getLogger(IconListRenderer.class);
    private Map<Object, Icon> icons = null;
    // End of variables declaration

    public IconListRenderer(Map<Object, Icon> icons) {
        this.icons = icons;
    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value, 
                        int index, boolean isSelected, boolean cellHasFocus) {

        // Get the renderer component from parent class

        JLabel label = (JLabel) super.getListCellRendererComponent(list,
                                        value, index, isSelected, cellHasFocus);

        // Get icon to use for the list item value
//        log.info(value);
        Icon icon = icons.get(value);

        // Set icon to display for value

        label.setIcon(icon);
        return label;
    }
}
